package com.room.search.web.rest;

import com.room.search.core.page.TableDataInfo;
import com.room.search.domain.RoomMenu;
import com.room.search.response.RoomResult;
import com.room.search.security.SecurityUtils;
import com.room.search.service.MenuService;
import com.room.search.web.rest.vm.LoginVM;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * REST controller for managing {@link com.room.search.domain.Menu}.
 */
@RestController
@RequestMapping("/api")
public class MenuResource {

    private final Logger log = LoggerFactory.getLogger(MenuResource.class);

    private final MenuService menuService;


    public MenuResource(MenuService menuService) {
        this.menuService = menuService;
    }

    @GetMapping("/menutest")
    public void menuTest(@Valid LoginVM loginVM) {
//        System.out.println(loginVM);
    }


    /**
     * 获取路由信息
     *
     * @return 路由信息
     */
    @GetMapping("/getRouters")
    public RoomResult getRouters()
    {
        String username = SecurityUtils.getCurrentUserLogin().orElse("");
        List<RoomMenu> all = menuService.findAll(username);
        log.info("所有的菜单menu={}", all);
        return RoomResult.success(menuService.buildMenus(all));
    }


    /**
     * 获取所有menu
     */
    @PreAuthorize("@ss.hasPermi('system:role:list')")
    @GetMapping("/menu/list")
    public RoomResult getAllMenu() {
        return menuService.getAllMenu();
    }
}
